package com.sitech.portal.system.dao.ibatis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.sitech.ibnms.core.BaseIbnmsDao;
import com.sitech.ibnms.core.IPage;
import com.sitech.ibnms.core.PageForm;
import com.sitech.ibnms.util.LabelValueBean;
import com.sitech.portal.system.dao.ISysRoleDao;
import com.sitech.portal.system.domain.TblSYS_ROLE;
import com.sitech.portal.system.domain.TblSYS_USER_ROLE;

public class SysRoleDaoImpl extends BaseIbnmsDao implements ISysRoleDao {

	public void add(TblSYS_ROLE tblSYS_ROLE) {
		this.insert("insertForTB_SYS_ROLE", tblSYS_ROLE);
	}

	public void addDept(TblSYS_ROLE tblSYS_ROLE) {
		this.insert("insertForTB_SYS_ROLE_DEPTID", tblSYS_ROLE);
	}

	public void update(TblSYS_ROLE tblSYS_ROLE) {
		this.update("updateForTB_SYS_ROLE", tblSYS_ROLE);
	}

	public void updateDept(TblSYS_ROLE tblSYS_ROLE) {
		this.update("updateForTB_SYS_ROLE_DEPTID", tblSYS_ROLE);
	}

	public void deleteRole(String roleId) {
		this.delete("deleteForTB_SYS_ROLE", roleId);
	}

	public void deleteDept(String roleId) {
		this.delete("deleteForTB_SYS_ROLE_DEPTID", roleId);
	}

	public TblSYS_ROLE findByPK(String roleID) {
		return (TblSYS_ROLE) this.querySingle(
					"findForTB_SYS_ROLEByPk", roleID);
	}

	public IPage findForList(PageForm pageForm) {


		return this.findPage("findForListByTB_SYS_ROLE", pageForm);
	}

	public List findForListToAll() {
		return this.query("findForListByTB_SYS_ROLEToAll",
					null);
	}

	public List findForListByDeptID() {
		return this.query("findForListByTB_SYS_ROLEByDeptID");
	}

	/**
	 * 取得部门名称
	 * 
	 * @return
	 */

	public List findDeptNameList() {
		return this.query("findDeptNameList");
	}

	public List findForRoleListByLonginId(TblSYS_USER_ROLE obj) {
		return this.query("findForRoleListByLonginId", obj);
	}

	public List findForOptions() {
		List list = new ArrayList();
		List roleList = findForListToAll();
		if (null != roleList) {
			for (int i = 0; i < roleList.size(); i++) {
				TblSYS_ROLE role = (TblSYS_ROLE) roleList.get(i);
				list.add(new LabelValueBean(role.getROLE_NAME(), role
						.getROLE_ID()));
			}
		}
		return list;

	}

	public List findForOptionsByManageUnitId(String[] manageUnitId) {
		List list = new ArrayList();
		List roleList = findForListByManageUnitId(manageUnitId);
		if (null != roleList) {
			for (int i = 0; i < roleList.size(); i++) {
				TblSYS_ROLE role = (TblSYS_ROLE) roleList.get(i);
				list.add(new LabelValueBean(role.getROLE_NAME(), role
						.getROLE_ID()));
			}
		}
		return list;

	}

	public List findForListByManageUnitId(String[] manageUnitId) {
		return this.query("findForListByTB_SYS_ROLEByManageUnitId", manageUnitId);
	}

	// start add by yuanky
	public IPage findByParentRoleId(String roleId, PageForm pageForm) {
		return this.findPage("findByParentRoleId", roleId, pageForm);
	}

	public List findNoPageByParentRoleId(String roleId) {
		return this.query("findNoPageByParentRoleId", roleId);
	}

	public int findCountByParentRoleId(String roleId) {
		Integer size = null;
		size = (Integer) this.querySingle(
					"findCountByParentRoleId", roleId);
		if (size == null) {
			return 0;
		} else {
			return size.intValue();
		}
	}

	// end add by yuanky

	public TblSYS_ROLE findForTB_SYS_ROLEByRoleId(String roleID) {
		return (TblSYS_ROLE) this.querySingle(
					"findForTB_SYS_ROLEByRoleId", roleID);
	}

    @Override
    public Boolean isAdmin(String login_id) {
        String num = (String)this.querySingle("isAdmin",login_id);
        if(num!=null && !("0").equals(num)){
            return true;
        }
        return  false;
    }
}
